// TreeTool.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "TreeStruct.h"

//

#if defined (_UNICODE) || defined (UNICODE)

	#define __T(x)      L ## x
#else
	#define __T(x)      x
#endif
void PrintChild(CTreeStruct* pNode,int i)
{
	for (int m = 0; m < i; m++)
	{
		printf(" ");
	}

#if defined (_UNICODE) || defined (UNICODE)
	wprintf(__T("%s\r\n"),TreeStruct_GetText(pNode));
#else
	printf("%s\r\n",TreeStruct_GetText(pNode));
#endif	
}

void EnumChild(CTreeStruct* pNode,int i)
{
	size_t nCount = TreeStruct_GetChildCount(pNode);
	for (size_t k = 0; k < nCount; k++)
	{
		CTreeStruct* pTemp = TreeStruct_GetChild(pNode,k);
		PrintChild(pTemp,i);
		if (TreeStruct_GetChildCount(pTemp) != 0)
		{
			EnumChild(pTemp,i+1);
		}
	}
}

int main(int argc, char* argv[])
{

	CTreeStruct* pTree = TreeStruct_Create();

	for (int i = 0; i < 2; i++)
	{
		CTreeStruct* pChild1 = TreeStruct_AddChildText(pTree,__T("1"));

		for (int j = 0; j < 2; j++)
		{
			TreeStruct_AddChildText(pChild1,__T("child[1][0]"));
		}
	}


//	
	
	std::string Data = TreeStruct_ToBin(pTree);
	TreeStruct_Destory(pTree);


	CTreeStruct* pNewTree = TreeStruct_Create();
	TreeStruct_FromBin(pNewTree,(void*)Data.data(),Data.size());
	EnumChild(pTree,0);
	TreeStruct_Destory(pNewTree);
	//printf("Hello World!\n");
	return 0;
}

